﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public abstract class Character  {
    protected CharacterAtrr m_attr;
    protected Weapon m_weapon;
    protected GameObject m_gameObject;
    protected NavMeshAgent m_navMeshAgent;
    protected AudioSource m_audioSource;
    protected Animation m_animation;

    public CharacterAtrr Attr { set { m_attr = value; } }
    public Vector3 Position
    {
        get { return m_gameObject.transform.position; }
    }
    public float AttackRange
    {
        get { return m_weapon.AttackRange; }
    }

    public void Update()
    {
        m_weapon.Update();
    }
    public abstract void UpdateFSMAI(List<Character> targets);
    public void Attack(Character target)
    {
        WeaponAttack(target);
        m_gameObject.transform.LookAt(target.Position);
        PlayAnimation("attack");
        target.UnderAttack(m_weapon.atkValue + m_attr.CritDmg);
    }
    public virtual void UnderAttack(float dmg)
    {
        m_attr.TakeDamage(dmg); //承受伤害
       

    }
  
    protected void WeaponAttack(Character target)
    {
        m_weapon.Fire(target.Position);
    }



    public void PlayAnimation(string name)
    {
        m_animation.CrossFade(name);
    }
    public void MoveTo(Vector3 positon)
    {
        m_navMeshAgent.SetDestination(positon);
        PlayAnimation("move");
    }




    public  void PlayEffect(string EffectName)
    {

    }
    public void PlaySound(string audioname)
    {

    }
    public void Killed()
    {

    }
}
